<!DOCTYPE html>
<meta charset="utf-8" />

<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="mpamng/term/queryTermFee.do" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">终端物理号:</label>
							<div class="search_input">
								<input id="search_terminalNo" type="text" name="terminalNo" placeholder="请输入终端物理号">
							</div>
						</div>
					
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作商名称:</label>
							<div class="search_input">
								<input id="search_agentName" type="text" name="agentName" placeholder="请输入合作商名称">
							</div>
						</div>
						
						<div class="search_elm">
							<label class="label_search" >终端状态:</label>
							<div class="search_input">
							    <select 
									 rel="obj.TERMINALSTATUS"
						 			 location="local" 
									 name="terminalStatus" 
						 			id="search_terminalStatus" 
						 			data-placeholder="请选择状态" style="width: 130px;vertical-align:middle;">
									<option value='' >----请选择----</option>
								</select>
							</div>
						</div>
						
						<div class="search_elm">
							<button class="btn btn-small btn_search" type="submit" title="搜索" > 搜索 </button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
	<div class="rowt">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			<div style="margin-top: 10px">
				<span id="auth_btn">
					<!-- <a auth="mpamng/term/addTermCom.do" class="btn btn-small btn-add" onclick="addTermCom();">新增</a> 
					<a auth="mpamng/term/deleteTermCom.do" class="btn btn-small btn-delete" onclick="deleteTermCom();">删除</a>
					
					<a  class="btn btn-small btn-delete" onclick="deleteTermFee();">删除终端费率</a>
					--> 
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>

		</div>
	</div>

	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({
				url : "mpamng/term/queryTermFee.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ '编号', '终端物理号', '合作商ID', '合作商名称','终端状态','民生类(0.38%)','一般类(0.78%)','批发类(0.78%)','批发类(封顶)','餐娱类(1.25%)','房产类(1.25%)','房产类(封顶)','操作' ],
				colModel : [ {name : 'terminalId',			index : 'terminalId',			width : '0px' ,hidden : true,sortable:false}, 
				             {name : 'terminalNo',			index : 'terminalNo',       	width : '150px' ,sortable:false},
				             {name : 'agentId',    	 		index : 'agentId',     			width : '120px' ,sortable:false,hidden : true},
				             {name : 'agentName',    	 		index : 'agentName',     			width : '120px' ,sortable:false},
				             {name : 'terminalStatus',     	index : 'terminalStatus',    	width : '100px' ,sortable:false,ditcKey:'TERMINALSTATUS', formatter : gridFormatByDict},
				             {name : 'rateLivelihood',     	index : 'rateLivelihood',     	width : '130px' ,sortable:false},
				             {name : 'rateGeneral',     	index : 'rateGeneral',     		width : '130px' ,sortable:false},
				             {name : 'rateGeneralTop',     	index : 'rateGeneralTop',     	width : '130px' ,sortable:false},
				             {name : 'rateGeneralMaximun',    index : 'rateGeneralMaximun',   width : '130px' ,sortable:false},
				             {name : 'rateEntertain',     	index : 'rateEntertain',     	width : '130px' ,sortable:false},
				             {name : 'rateEntertainTop',    index : 'rateEntertainTop',     width : '130px' ,sortable:false},
				             {name : 'rateEntertainMaximun',    index : 'rateEntertainMaximun',   width : '130px' ,sortable:false},
				             {name : 'myac',        		index : '',          			width : '140px', formatter:optionEdit}
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,
				shrinkToFit:false,
				multiselect : true,//设置行可多选的 
				multiboxonly : true,//

				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});
			var termFeeCode=0;
			function termFeeCodeFormat(cellvalue, options, rowObject){
				if(cellvalue==null||cellvalue=='null'||cellvalue.length<=0){
					termFeeCode=0;
					return "--";
				}else{
					termFeeCode=1;
					return "是";
				}
			}
			//定义按钮
			function optionEdit(cellvalue, options, rowObject) {
				if(rowObject["agentId"] != null){
					var button = "<div class=\"hidden-sm hidden-xs btn-group\">";  //定义button
					button += "<button class='btn btn-xs btn-warning'  title='详细信息查看' onclick='termFeeView(\""+rowObject["terminalId"]+"\",\""+rowObject["agentId"]+"\");'>详细</button>";
					button += "<button class='btn btn-xs btn-warning'  title='修改' onclick='updateTermFee(\""+rowObject["terminalId"]+"\",\""+rowObject["agentId"]+"\");'>修改</button>";
					button += "</div>";
					return button;
				}else{
					return "";
				}
			}
		});

		//查询终端费率
		function termFeeView(termId,agentId) {
			openDialog({
				dialogId : 'dlg-termFeeEdit',
				title : '编辑终端费率',
				pageUrl : 'mpamng/term/termFeeView.do',
				dataUrl : 'mpamng/term/queryTermFeeById.do',
				width : '65%',
				height:'80%',
				dataParam : {
					termId : termId,
					agentId : agentId,
					type:'view'
				},pageParam: {
					type:'view'
				},
				dataName : 'obj,map' //表单数据存储对象名称
			});
		}
		
		//修改
		function updateTermFee(termId,agentId) {
			if(termId.length<=0){
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			openDialog({
				dialogId : 'dlg-termFeeEdit',
				title : '编辑终端费率',
				pageUrl : 'mpamng/term/termFeeView.do',
				dataUrl : 'mpamng/term/queryTermFeeById.do',
				width : '65%',
				height:'80%',
				dataParam : {
					termId : termId,
					agentId : agentId,
					type:'eidt'
				},
				pageParam: {
					type:'edit',
					agentId:agentId
				},
				dataName : 'obj,map' //表单数据存储对象名称
			});
		}
		//用户删除
		function deleteTermFee() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}
			
			var ids = "";
			for (var i = 0; i < rows.length; i++) {
				　ids += $('#grid-table').jqGrid('getRowData',rows[i]).terminalId+ ",";
			}
			ids = ids.substring(0, ids.lastIndexOf(","));
			msg.confirm({title:'确认',position:'center',msg:'您确定要删除选中终端费率吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
						url : "mpamng/term/deleteTermFee.do?termIds=" + ids,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
			}
	</script>